<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" th:replace="~{common/base :: layout(~{::title}, ~{::content}, ~{::style}, ~{::script})}">
<head>
    <title>商品分类 - 优选商城</title>
    <style th:fragment="style">
        .category-container {
            padding: 30px 0;
        }
        .category-sidebar {
            background-color: #f8f9fa;
            border-radius: 8px;
            padding: 20px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.05);
        }
        .category-sidebar .list-group-item {
            border: none;
            background: transparent;
            border-radius: 6px;
            margin-bottom: 5px;
            transition: all 0.3s ease;
        }
        .category-sidebar .list-group-item:hover {
            background-color: #e9ecef;
            transform: translateX(5px);
        }
        .category-sidebar .list-group-item.active {
            background-color: #1e3c72;
            color: white;
            font-weight: 500;
        }
        .category-sidebar .list-group-item i {
            margin-right: 10px;
        }
        .product-card {
            border: none;
            border-radius: 8px;
            transition: all 0.3s ease;
            margin-bottom: 20px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.05);
        }
        .product-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 5px 15px rgba(0,0,0,0.1);
        }
        .product-image {
            height: 200px;
            object-fit: cover;
            border-top-left-radius: 8px;
            border-top-right-radius: 8px;
        }
        .product-title {
            font-size: 1.1rem;
            font-weight: 500;
            margin-bottom: 10px;
            height: 48px;
            overflow: hidden;
            display: -webkit-box;
            -webkit-line-clamp: 2;
            -webkit-box-orient: vertical;
        }
        .product-price {
            color: #e44d26;
            font-weight: 600;
            font-size: 1.2rem;
        }
        .product-meta {
            display: flex;
            justify-content: space-between;
            font-size: 0.85rem;
            color: #6c757d;
        }
        .no-products {
            padding: 50px 0;
            text-align: center;
            color: #6c757d;
        }
        .category-title {
            display: flex;
            align-items: center;
            margin-bottom: 25px;
            padding-bottom: 15px;
            border-bottom: 1px solid #e9ecef;
        }
        .category-title i {
            font-size: 1.5rem;
            margin-right: 10px;
            color: #1e3c72;
        }
        .category-title h2 {
            margin: 0;
            font-weight: 600;
        }
    </style>
</head>
<body>
    <div th:fragment="content">
        <div class="container category-container">
            <div class="row">
                <!-- 左侧分类导航 -->
                <div class="col-md-3 mb-4">
                    <div class="category-sidebar">
                        <h4 class="mb-3">商品分类</h4>
                        <div class="list-group">
                            <a th:each="category : ${categories}" 
                               th:href="@{/category/{id}(id=${category.id})}" 
                               class="list-group-item list-group-item-action"
                               th:classappend="${currentCategory != null && currentCategory.id == category.id ? 'active' : ''}">
                                <i class="bi" th:classappend="${category.icon != null and !category.icon.isEmpty() ? category.icon : 'bi-tag'}"></i>
                                <span th:text="${category.name}">分类名称</span>
                            </a>
                        </div>
                    </div>
                </div>
                
                <!-- 右侧商品列表 -->
                <div class="col-md-9">
                    <!-- 错误信息显示 -->
                    <div th:if="${error != null}" class="alert alert-danger" role="alert">
                        <i class="bi bi-exclamation-triangle-fill me-2"></i>
                        <span th:text="${error}">错误信息</span>
                    </div>
                    
                    <div th:if="${currentCategory != null}" class="category-title">
                        <i class="bi" th:classappend="${currentCategory.icon != null and !currentCategory.icon.isEmpty() ? currentCategory.icon : 'bi-tag'}"></i>
                        <h2 th:text="${currentCategory.name}">分类名称</h2>
                    </div>
                    
                    <div th:if="${products != null and !products.isEmpty()}" class="row">
                        <div th:each="product : ${products}" class="col-md-4 col-6">
                            <div class="card product-card">
                                <a th:href="@{/product/{id}(id=${product.id})}">
                                    <img th:src="${product.mainImage}" class="card-img-top product-image" alt="商品图片">
                                </a>
                                <div class="card-body">
                                    <a th:href="@{/product/{id}(id=${product.id})}" class="text-decoration-none text-dark">
                                        <h5 class="product-title" th:text="${product.name}">商品名称</h5>
                                    </a>
                                    <p class="product-price" th:text="${'¥' + product.price}">¥199.00</p>
                                    <div class="product-meta">
                                        <span th:text="${'销量: ' + product.sales}">销量: 100</span>
                                        <span th:text="${'库存: ' + product.stock}">库存: 50</span>
                                    </div>
                                    <div class="d-grid gap-2 mt-3">
                                        <a th:href="@{/product/detail/{id}(id=${product.id})}" class="btn btn-primary btn-sm">查看详情</a>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    
                    <div th:if="${products == null or products.isEmpty()}" class="no-products">
                        <i class="bi bi-emoji-frown" style="font-size: 3rem;"></i>
                        <h4 class="mt-3">暂无商品</h4>
                        <p>该分类下暂时没有商品，请查看其他分类</p>
                    </div>
                    
                    <!-- 分页控件 -->
                    <div th:if="${total > 0}" class="d-flex justify-content-center mt-4">
                        <nav aria-label="Page navigation">
                            <ul class="pagination">
                                <li class="page-item" th:classappend="${current == 1 ? 'disabled' : ''}">
                                    <a class="page-link" th:href="@{/category/{id}(id=${currentCategory.id}, page=${current - 1}, size=${size})}" aria-label="Previous">
                                        <span aria-hidden="true">&laquo;</span>
                                    </a>
                                </li>
                                <li class="page-item" th:each="i : ${#numbers.sequence(1, pages)}"
                                    th:classappend="${i == current ? 'active' : ''}">
                                    <a class="page-link" th:href="@{/category/{id}(id=${currentCategory.id}, page=${i}, size=${size})}" th:text="${i}">1</a>
                                </li>
                                <li class="page-item" th:classappend="${current == pages ? 'disabled' : ''}">
                                    <a class="page-link" th:href="@{/category/{id}(id=${currentCategory.id}, page=${current + 1}, size=${size})}" aria-label="Next">
                                        <span aria-hidden="true">&raquo;</span>
                                    </a>
                                </li>
                            </ul>
                        </nav>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <script th:fragment="script">
        $(document).ready(function() {
            // 初始化Bootstrap的Toast
            $('.toast').toast({
                autohide: true,
                delay: 3000
            });
            $('.toast').toast('show');
            
            // 处理分页点击事件
            $('.pagination .page-link').on('click', function(e) {
                if ($(this).parent().hasClass('disabled')) {
                    e.preventDefault();
                }
            });
        });
    </script>
</body>
</html> 